home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
- From: Dan Pop <danpop@mail.cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: Fastest way to computer log(base2) of x?
- Date: Fri, 2 Feb 1996 13:38:45 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9602021238.AA01292@dxmint.cern.ch>
- References: <4e61iu$p6e@villa.fc.net> <4e6p7t$1n72@cymbal.aix.calpoly.edu> <4e8r54$n8q@ns.RezoNet.NET>,<4e9bl4$3ccp@cymbal.aix.calpoly.edu> <DM0AKu.A2H@news.cern.ch> <4eqvr1$7tn@news.microsoft.com>
- X-NNTP-Posting-Host: hpl3sn03.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
-
- a-cnadc@microsoft.com (Dann Corbit) writes:
-
- >Just a note that none of theses methods really find the base 2
- >log of a number unless the number is a power of 2. It is only
- >a crude approximation of the log most of the time. You are
- >finding the highest bit, that is all. NOT the log base 2.
-
- And this is precisely what the original poster was asking for:
-
- I am trying to find out what could be the fastest way to compute
- the position of the highest bit in any given integer -- basically, the
- logarithm to the base 2 of any number.
-
- The position of the highest bit happens to be (int)(log base 2) if the
- bit positions are counted from zero (i.e. the lsb is bit 0).
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-